package com.os.sys.util;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class CreateJwt {
    public static void main(String[] args) {
        /**
         * ID:用户ID
         * Subject:用户名
         * IssuedAt
         * SignWith:头部信息，声明算法，盐    依据这些信息，会生成签名
         */
        JwtBuilder jwtBuilder = Jwts.builder()
                .setId("666")
                .setSubject("小马")
                .setIssuedAt(new Date())
                .signWith(SignatureAlgorithm.HS256, "itcast")
                .setExpiration(new Date(new Date().getTime()+6000000))
                .claim("role", "admin");
        //生成的结果
        System.out.println(jwtBuilder.compact());
    }
}
